package com.itheima.demo6;

public class Foodie extends  Thread {
    @Override
    public void run() {

        while (true){
            synchronized (Desk.lock){
                if (Desk.count == 0){
                    break;
                }else {
                    if (Desk.foodFlog == 0){
                        try {
                            Desk.lock.wait();//将当前线程和锁进行绑定
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //把吃的总数减一
                        Desk.count--;
                        //开吃
                        System.out.println("吃货正在吃饭，还能吃"+Desk.count+"碗！！");
                        //唤醒厨师继续做
                        Desk.lock.notifyAll();
                        //修改桌子的状态
                        Desk.foodFlog = 0;
                    }
                }
            }
        }

    }
}
